from flask import Flask
from flask_cors import CORS

from src.exts import db
from src.conf.conf import AppConfig
from src.controllers import auth_controller
from src.controllers import blog_controller


def create_app():
    """
    工厂函数，插拔式添加配置和应用
    :return: Flask(__name__)对象
    """
    """创建Flask应用实例"""
    app_ = Flask(__name__)
    # app_.default_config

    """应用配置"""
    app_.config.from_object(AppConfig)

    """db绑定app"""
    db.init_app(app_)
    
    """解决跨域问题"""
    CORS(app_, resources=r"/*")

    """注册蓝图"""
    app_.register_blueprint(auth_controller.bp)
    app_.register_blueprint(blog_controller.bp)
    
    """url引入"""
    app_.add_url_rule("/", endpoint="index", view_func=blog_controller.index)
    return app_
